<!--执行中-->
<template>
  <div class="all">
    <SubMenuOval class="menu" :menus="menus" :menu="menu" @menuClick="menuClick"></SubMenuOval>

    <HRunStrategy class="strategy" v-if="menu == 0" 
    v-model="strategy" @copy="httpUserInfo"/>

    <HRunTrust class="trust" ref="Run" v-else />
  </div>
</template>

<script>
//组件
import SubMenuOval from '@/public/view/SubMenuOval.vue'
import HRunStrategy from '@/run/HRunStrategy.vue' 
import HRunTrust from '@/run/HRunTrust.vue' 

//功能
const weexFunction = weex.requireModule("WeexFunction");
//功能
import jnavigator from "@/_js/navigator";
import jmodal from "@/_js/modal";
import jhttps from "@/_js/https";

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T("执行历史"));

export default {

  components: {
    SubMenuOval,
    HRunStrategy,
    HRunTrust,
  },

  data() {
    return {
      T:T,
      menus:[T('策略'), T('量化托管')],
      menu:0,
    };
  },

  mounted() {
  },
  
  methods: {
    
    /********************************** https*/
    //http用户信息
    httpUserInfo(item) {

      jmodal.showLoad();
      var param = {};
      jhttps.postX("userV2/userDetail", param, true,(data) => {
        if (data.status == 200) {
          data = data.data;
          var info = data.account;
          if (info.member != 'LV0') {
            this.httpExecuteDetail(item);
          } else {
             var parm = {message:T('开通VIP后才能使用参数复制功能，是否前往开启？'),
                        okBtn:T("前往"), cancelBtn:T("取消")};
            jmodal.confirm(parm, (bool)=>{
              if(bool == "true") {
                jnavigator.open('', "mine/Vip", {}, {'navColor':'#1677fe'});
              }
            });
          }
        } else {
          jmodal.hideLoad();
          jmodal.toast(data.msg);
        }
      });
    },

    //http执行详情
    httpExecuteDetail(item) {
      
      var param = {'executeId': item.executeId};
      jhttps.post("strategyV3/executeHistoryDetail",param,true,(data) => {

          jmodal.hideLoad();
          if (data.status == 200) {
            data = data.data;
            var config = data.executeHistoryDetail.config;
            item.config = config;
            this.copyUp(item);
          } else {
           jmodal.toast(data.msg);
          }
        }
      );
    },

    /********************************** 点击触发*/
    //菜单点击
    menuClick(menu){
      this.menu = menu;
    },

    //复制启动
    copyUp(item) {

      weexFunction.debugLog(item);
      // return;

      var copy = {'strategyId':item.strategyId, 'strategyName':item.strategyName, 'copyConfig':item.config};
      var dict = {'网格交易': 'up/SUpGrid',
                    '海浪网格': 'up/SUpSea',
                    '马丁追踪': 'up/SUpMd',
                    '区间套利': 'up/SUpQj',
                    '恒量定投': 'up/SUpWeigh',
                    '海风马丁': 'up/SUpHf',
                    '币本位海风马丁': 'up/SUpHfTb',
                    'DCA智能策略': 'up/SUpTy'};
      var url = item.isContract == 'spot' ?  dict[copy.strategyName] : 'upContract/CUp';
      if (!url){
        jmodal.toast('无法复制非官方策略');
        return;
      }
      jnavigator.open(copy.strategyName, url, copy);
    }
  },
};

</script>


<style src="@/_css/style.css"></style>
<style scoped>
.menu {
  margin-top: 20px;
  margin-left: 20px;
}
.strategy{
  margin-top: 40px;
  flex: 1;
}
.trust{
  margin-top: 40px;
  flex: 1;
}
</style>